Skip to content

std::absに表現不可能な値(INT_MIN等)を渡した際の未定義動作について追記#1600

Merged
teruyamato0731 merged 4 commits intomasterfrom
feat/abs-int-min-ub
Apr 3, 2026
Merged

std::absに表現不可能な値(INT_MIN等)を渡した際の未定義動作について追記#1600
teruyamato0731 merged 4 commits intomasterfrom
feat/abs-int-min-ub

Conversation

@teruyamato0731
Copy link
Copy Markdown
Contributor

@teruyamato0731 teruyamato0731 commented Apr 3, 2026

概要

<cstdlib><cmath>std::abs のページについて、以下の記述改善・追記を行います。

表現不可能な値(INT_MIN等)を渡した際の未定義動作の追記

引数の絶対値が戻り値の型で表現できない場合、C/C++標準規格において未定義動作とされています。とくに一般的な2の補数表現のシステムにおいて std::abs(INT_MIN) などとした場合にオーバーフローが発生し未定義動作となることは、躓きやすい落とし穴であるため ## 備考 に明記しました。

出典:

C11標準規格ドラフト(N1570) 7.22.6.1

The abs, labs, and llabs functions compute the absolute value of an integer j. If the result cannot be represented, the behavior is undefined.
304) The absolute value of the most negative number cannot be represented in two's complement.
(訳:abs、labs、llabs関数は整数 j の絶対値を計算する。その結果が表現できない場合、動作は未定義である。)

image

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

プレビュー (HTML) (更新時刻: 2026-04-03 10:58:01 JST)

  • Commit: 81de6e3
  • プレビューの生成には時間がかかります (3~5分)。進捗状況はこちらをご確認ください。

変更記事一覧

5件の記事が変更されました。

※ソース (.md) に直接変更のあった記事を列挙しています。グローバル修飾や変換規則の変更による変化は考慮していません。

Copy link
Copy Markdown
Member

@faithandbrave faithandbrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

@teruyamato0731 teruyamato0731 merged commit 486647f into master Apr 3, 2026
20 checks passed
@teruyamato0731 teruyamato0731 deleted the feat/abs-int-min-ub branch April 3, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants